<%@ Page Title="Right_RoleRight List" Language="C#" AutoEventWireup="true" CodeBehind="Right_RoleRightList.aspx.cs" Inherits="Youz.CreditRepay.Manage.Right_RoleRightList" %>

<script>
    //loadCSS("assets/plugins/gritter/css/jquery.gritter.css");

    var requireJS = [
        //"assets/plugins/gritter/js/jquery.gritter.min.js"
    ];

    loadJS(requireJS);
</script>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading" data-original-title>
                <h2><i class="fa fa-align-justify"></i><span style="font-size: 16px; padding-right: 15px;"><%: R(LanguageModule.Right_RoleRight, "Right_RoleRight", "Right_RoleRight") %></span></h2>
                <div class="panel-actions"></div>
            </div>
            <div class="panel-body">
                <div class="alert alert-danger" style="display: none;">
                    <button type="button" class="close" data-dismiss="alert">×</button><strong><i class="fa fa-warning"></i></strong><span class="content"></span>
                </div>
                <div class="col-sm-4">
                    <%-- <div class="form-group">
                        <div class="input-group">
                            <input type="email" id="input2-group2" name="input2-group2" class="form-control" placeholder="Search..."><span class="input-group-btn">
                                <button type="button" class="btn btn-primary">
                                <i class="fa fa-search "></i>
                                <%: R(LanguageModule.M_Common, "Query") %></button></span>
                        </div>
                    </div>--%>
                </div>
                <div class="col-sm-12">
                    <div class="form-group">
                        <a href="#" class="btn btn-info" id="btnEdit"><i class="fa fa-edit "></i>保存权限</a>
                    </div>
                </div>
                <div class="col-sm-3">
                    <table id="table" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%"></table>
                </div>
                <div class="col-sm-9">
                    <table id="tableMenu" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%"></table>
                </div>

            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var dt;
    var dt2;

    $(function () {
        dt = $('#table').DataTable({
            "paging": false,
            "info": false,
            "ajax": {
                "url": 'Right/Handlers/Right_RoleinfoHandler.ashx?type=list',
                "type": "POST",
                "dataSrc": "data",
                "data": function (d) {
                }
            },
            "columns": [

                    { "data": 'RoleID', "title": "<%: R(LanguageModule.Right_Roleinfo, "RoleID", "角色ID") %>", visible: false },
                    { "data": 'RoleName', "title": "<%: R(LanguageModule.Right_Roleinfo, "RoleName", "角色名称") %>" },
                    { "data": 'IsSystem', "title": "<%: R(LanguageModule.Right_Roleinfo, "IsSystem", "IsSystem") %>", render: fYesNo },
                    { "data": 'IsDefault', "title": "<%: R(LanguageModule.Right_Roleinfo, "IsDefault", "IsDefault") %>", render: fYesNo },
            ]
        });

        dt2 = $('#tableMenu').DataTable({
            "paging": false,
            "info": false,
            "ajax": {
                "url": 'Right/Handlers/Right_MenuHandler.ashx?type=list&st=1',
                "type": "POST",
                "dataSrc": "data",
                "data": function (d) {
                }
            },
            "columns": [
                    {
                        data: "MenuID",
                        title: '<input type="checkbox" class="editor-active" id="all">',
                        width: 25,
                        render: function (data, type, row) {
                            return "<input type='checkbox' name='menu' class='" + row.MenuID + "' value='" + row.MenuID + "'> ";
                        },
                        className: "dt-body-center"
                    },
                    { "data": 'MenuID', "title": "<%: R(LanguageModule.Right_Menu, "MenuID", "MenuID") %>", visible: false },
                    { "data": 'MenuNameEn', "title": "<%: R(LanguageModule.Right_Menu, "MenuName", "菜单名称") %>" },
                    { "data": 'MenuURL', "title": "<%: R(LanguageModule.Right_Menu, "MenuURL", "菜单路径") %>" },
                    { "data": 'Sort', "title": "<%: R(LanguageModule.Right_Menu, "Sort", "排序") %>" },
                    { "data": 'IsEnabled', "title": "<%: R(LanguageModule.Right_Menu, "IsEnabled", "IsEnabled") %>", render: fYesNo },
                    { "data": 'ModifiedTime', "title": "<%: R(LanguageModule.Right_Menu, "ModifiedTime", "修改时间") %>" },
            ],
            rowCallback: function (row, data) {
                // Set the checked state of the checkbox in the table
                $(row).find('input:checkbox').prop('checked', false);
            }
        });

        //点击行事件
        var roleId = 0;
        //$('#table tbody').on('click', 'tr', function () {
        //    if (dt.row('.selected').data() != null) {
        //        roleId = dt.row('.selected').data().RoleID;
        //        $.post("Right/Handlers/Right_RoleRightHandler.ashx?type=list", { roleId: roleId }, function (data) {
        //            $("input").each(function () {
        //                $("input[name='menu']").prop("checked", false);
        //            });
        //            if (data.checkMenuInfo != "") {
        //                var menuarr = data.checkMenuInfo.split(',');
        //                $("input").each(function () {
        //                    for (var i = 0; i < menuarr.length; i++) {
        //                        //if (eval($(this).val()) == eval(menuarr[i])) {
        //                        //    $(this).prop("checked", true);
        //                        //}
        //                        $("input." + menuarr[i] + "").prop('checked', true);
        //                    }

        //                });
        //            }
        //        }, 'json');
        //    }
        //});
        //点击行事件
        $('#table tbody tr').live('click', function () {
            if (dt.row('.selected').data() != null) {
                roleId = dt.row('.selected').data().RoleID;
                $.post("Right/Handlers/Right_RoleRightHandler.ashx?type=list", { roleId: roleId }, function (data) {
                    $("input").each(function () {
                        $("input[name='menu']").prop("checked", false);
                    });
                    if (data.checkMenuInfo != "") {
                        var menuarr = data.checkMenuInfo.split(',');
                        $("input").each(function () {
                            for (var i = 0; i < menuarr.length; i++) {
                                //if (eval($(this).val()) == eval(menuarr[i])) {
                                //    $(this).prop("checked", true);
                                //}
                                $("input." + menuarr[i] + "").prop('checked', true);
                            }

                        });
                    }
                }, 'json');
            }
        });


        //保存
        $('#btnEdit').click(function () {
            if ($('#table tbody tr.selected').length > 0) {
                jconfirm("<%: R(LanguageModule.Right_RoleRight, "saveright_tips2","权限模块,请谨慎操作,如有疑问,请联系技术!您确定要继续操作吗？") %>", function () {
                    var menuInfos = "";
                    $("input[name='menu']:checked").each(function () {
                        menuInfos = menuInfos + this.value + ",";
                    });
                    if (menuInfos == "") {
                        $(".alert > .content").html("<%: R(LanguageModule.Right_RoleRight, "saveright_tips4","对不起，还未选取任何菜单！") %>");
                        $(".alert").show();
                        return false;
                    }
                    $.post("Right/Handlers/Right_RoleRightHandler.ashx?type=save", { roleID: roleId, menuInfosID: menuInfos }, function (data) {
                        $(".alert > .content").html(data.message);
                        $(".alert").show();
                    }, 'json');
                });
            }
            else {
                $(".alert > .content").html("<%: R(LanguageModule.Right_RoleRight, "saveright_tips3","对不起,您还未选择角色！") %>");
                $(".alert").show();
            }
        });

        //全选/取消全选
        $('#all').toggle(function () {
            $("input[name='menu']").prop("checked", true);
        }, function () {
            $("input[name='menu']").removeAttr("checked");
        });

    });
</script>
